package internal

import (
	"Alpaca/gate"
	"Alpaca/log"
	"reflect"
	"server/msg"
)

func init() {
	handler(&msg.LoginMsg{}, hanleLogin)
}

func handler(m interface{}, h interface{}) {
	skeleton.RegisterChanRPC(reflect.TypeOf(m), h)
}

func hanleLogin(args []interface{}) {
	m := args[0].(*msg.LoginMsg)
	a := args[1].(gate.Agent)

	account := m.Account
	passwd := m.Password

	if account == "Alpaca" && passwd == "123456" {
		log.Debug("user %v is login", account)
		a.WriteMsg(&msg.UidMsg{
			Uid: 1,
		})
	} else {
		log.Debug("user %v password is not corret", account)
		a.WriteMsg(&msg.UidMsg{
			Uid: -1,
		})
	}
}
